package cn.hchaojie.boot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.hchaojie.boot.convert.DateConverter;

// java配置类必须的注解
@Configuration
public class WebConfigurer implements WebMvcConfigurer {
	/**
	 * 配置跨域访问
	 * */
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
			.allowedOrigins("http://localhost:9527", "http://127.0.0.1:9527")
			.allowedMethods("DELETE", "POST", "PUT", "GET");
	}
	
	@Override
	public void addFormatters(FormatterRegistry registry) {
		registry.addConverter(new DateConverter());
	}
}
